package njust.csc.aecore

import njust.csc.aecore.analysis.DynamicExplorer
import njust.csc.aecore.utils.PathUtils
import kotlin.io.path.readLines

/**
 * @Author ZhouHang
 * @Date 24/6/4 周二
 * 动态抓包脚本
 */
fun main() {
//    val apkInfo = "{\"absolutePath\":\"N:\\\\Code\\\\PL\\\\StaticAnalysis\\\\ApkExplorer\\\\input\\\\gamble\\\\1ace25ed992a997d43362ed4f0665e95.apk\",\"name\":\"金鼎娱乐城\",\"packageName\":\"com.cashwebappjinDingYLC\",\"size\":24523,\"versionInfo\":{\"versionCode\":1,\"versionName\":\"1.0.0\",\"minSdkVersion\":16,\"targetSdkVersion\":28,\"compileSdkVersion\":28},\"permissions\":[\"android.permission.INTERNET\",\"android.permission.ACCESS_NETWORK_STATE\",\"android.permission.WAKE_LOCK\",\"android.permission.ACCESS_WIFI_STATE\",\"com.android.vending.CHECK_LICENSE\",\"android.permission.WRITE_EXTERNAL_STORAGE\"],\"v1SignatureInfo\":{\"name\":\"CERT.RSA\",\"signatureFileName\":\"META-INF/CERT.SF\",\"certification\":{\"subject\":\"CN=1\",\"signatureType\":\"SHA256withRSA\",\"md5\":\"66 BE DA 48 2C 14 5C 9B B6 FE A4 83 83 8C 1A E0 \",\"sha1\":\"DE 57 DA 7A AC 68 9B E3 47 83 FA A0 10 9D 8C 9B 51 8D 83 74 \",\"sha256\":\"63 AA 36 63 A1 EF DD 49 80 78 41 85 C1 E7 38 15 95 64 CB FF E3 EC 05 0C FC 46 90 AE 4B CB 52 BB \"}},\"v2SignatureInfo\":{\"index\":0,\"certification\":{\"subject\":\"CN=1\",\"signatureType\":\"SHA256withRSA\",\"md5\":\"66 BE DA 48 2C 14 5C 9B B6 FE A4 83 83 8C 1A E0 \",\"sha1\":\"DE 57 DA 7A AC 68 9B E3 47 83 FA A0 10 9D 8C 9B 51 8D 83 74 \",\"sha256\":\"63 AA 36 63 A1 EF DD 49 80 78 41 85 C1 E7 38 15 95 64 CB FF E3 EC 05 0C FC 46 90 AE 4B CB 52 BB \"}},\"time\":13.977}\n"
    val apkInfo = "{\"absolutePath\":\"N:\\\\Code\\\\PL\\\\StaticAnalysis\\\\ApkExplorer\\\\input\\\\userInput\\\\HBD.apk\",\"relativePath\":\"userInput\\\\HBD.apk\",\"size\":37958,\"urls\":[\"https://graph.qq.com/\",\"https://api.weixin.qq.com/\",\"https://h.trace.qq.com/kv\",\"https://huatuocode.huatuo.qq.com?domain=mobile.opensdk.com&cgi=opensdk&type=\",\"https://wspeed.qq.com/w.cgi\",\"http://schemas.android.com/apk/res/android\",\"https://issuetracker.google.com/issues/116541301\",\"http://ns.adobe.com/xap/1.0/\",\"https://issuetracker.google.com/issues/new?component=413107&template=1096568\",\"https://ulogs.umeng.com\",\"https://ulogs.umengcloud.com\",\"https://doh.pub/dns-query\",\"https://dns.alidns.com/dns-query\",\"https://dns.quad9.net/dns-query\",\"https://dns.adguard-dns.com/dns-query\",\"https://developer.umeng.com/docs/66632/detail/\",\"https://appsupport.qq.com/cgi-bin/qzapps/mapp_addapp.cgi\",\"https://openmobile.qq.com/\",\"https://cgi.connect.qq.com/qqconnectopen/openapi/policy_conf\",\"http://xml.apache.org/xslt\",\"https://aomedia.org/emsg/ID3\",\"https://developer.apple.com/streaming/emsg-id3\",\"http://schemas.android.com/apk/res-auto\",\"https://www.hao123.com/api/gethitthecity\",\"https://www.hao123.com/api/citymenu\",\"https://www.hao123.com/api/getgoodthing\",\"https://www.hao123.com/api/tnwhilte\",\"https://www.hao123.com/api/sample\",\"https://www.hao123.com/api/getgamedata\",\"https://www.hao123.com/api/getgameboxindexdata\",\"https://vd6.l.qq.com/proxyhttp\",\"https://www.sina.com.cn/api/hotword.json\",\"https://gw.m.163.com/search/api/v1/pc-wap/rolling-word\",\"https://photo.home.163.com/api/designer/pc/home/index/word\",\"https://ac.dun.163.com/v3/d\",\"https://www.zhihu.com/api/v4/search/top_search\",\"https://ranks.hao.360.com/shortvideo-api/hotnews\",\"https://api.bilibili.com/x/web-interface/nav\",\"https://api-push.meizu.com/garcia/api/server/getPublicKey\",\"https://api-push.in.meizu.com\",\"https://api-push.meizu.com\",\"https://norma-external-collect.meizu.com/android/exchange/getpublickey.do\",\"https://norma-external-collect.meizu.com/push/android/external/add.do\",\"https://open.weixin.qq.com/connect/sdk/qrconnect?appid=%s&noncestr=%s&timestamp=%s&scope=%s&signature=%s\",\"https://long.open.weixin.qq.com/connect/l/qrconnect?f=json&uuid=%s\",\"https://mdc.html5.qq.com/mh?channel_id=50079&u=\",\"https://pslog.umeng.com\",\"http://xmlpull.org/v1/doc/features.html#process-namespaces\",\"https://exoplayer.dev/issues/player-accessed-on-wrong-thread\",\"https://log.tbs.qq.com/ajax?c=pu&v=2&k=\",\"https://log.tbs.qq.com/ajax?c=pu&tk=\",\"https://log.tbs.qq.com/ajax?c=dl&k=\",\"https://tbsrecovery.imtt.qq.com/getconfig\",\"http://dashif.org/guidelines/last-segment-number\",\"https://api-push.meizu.com/garcia/api/client/log/upload\",\"https://%1\",\"https://resolver.msg.xiaomi.net/psc/?t=a\",\"http://playready.directtaps.net/pr/svc/rightsmanager.asmx\",\"http://schemas.microsoft.com/DRM/2007/03/protocols/AcquireLicense\",\"https://api-push.meizu.com/garcia/api/client/message/registerPush\",\"https://api-push.meizu.com/garcia/api/client/message/unRegisterPush\",\"https://api-push.meizu.com/garcia/api/client/message/getRegisterSwitch\",\"https://api-push.meizu.com/garcia/api/client/message/changeRegisterSwitch\",\"https://api-push.meizu.com/garcia/api/client/message/changeAllSwitch\",\"https://api-push.meizu.com/garcia/api/client/message/subscribeTags\",\"https://api-push.meizu.com/garcia/api/client/message/unSubscribeTags\",\"https://api-push.meizu.com/garcia/api/client/message/unSubAllTags\",\"https://api-push.meizu.com/garcia/api/client/message/getSubTags\",\"https://api-push.meizu.com/garcia/api/client/message/subscribeAlias\",\"https://api-push.meizu.com/garcia/api/client/message/unSubscribeAlias\",\"https://api-push.in.meizu.com/garcia/api/client/message/registerPush\",\"https://api-push.in.meizu.com/garcia/api/client/message/unRegisterPush\",\"https://api-push.in.meizu.com/garcia/api/client/message/getRegisterSwitch\",\"https://api-push.in.meizu.com/garcia/api/client/message/changeRegisterSwitch\",\"https://api-push.in.meizu.com/garcia/api/client/message/changeAllSwitch\",\"https://api-push.in.meizu.com/garcia/api/client/message/subscribeTags\",\"https://api-push.in.meizu.com/garcia/api/client/message/unSubscribeTags\",\"https://api-push.in.meizu.com/garcia/api/client/message/unSubAllTags\",\"https://api-push.in.meizu.com/garcia/api/client/message/getSubTags\",\"https://api-push.in.meizu.com/garcia/api/client/message/subscribeAlias\",\"https://api-push.in.meizu.com/garcia/api/client/message/unSubscribeAlias\",\"https://imgcache.qq.com/ptlogin/static/qzsjump.html\",\"https://github.com/ReactiveX/RxJava/wiki/What\",\"https://openmobile.qq.com/oauth2.0/m_jump_by_version\",\"http://%s:%d/%s\",\"https://github.com/danikula/AndroidVideoCache/issues/134\",\"https://github.com/danikula/AndroidVideoCache/issues/88\",\"https://github.com/danikula/AndroidVideoCache/issues/43\",\"https://github.com/danikula/AndroidVideoCache/issues\",\"http://www.w3.org/ns/ttml#parameter\",\"www.baidu.com:80\"],\"time\":32.675}\n"
    DynamicExplorer().fromApk(apkInfo)

//    batchDynamicExplore("scam")
}

/**
 * 批量动态分析
 * */
fun batchDynamicExplore(relativePath: String) {
    for (line in PathUtils.getBaseInfoPath(relativePath, false).readLines()) {
        DynamicExplorer().fromApk(line)
    }
}

